package cglib;

import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.CallbackFilter;
import net.sf.cglib.proxy.Enhancer;

import java.lang.reflect.Method;

public class EnhancerUse {

    public static void main(String[] args) {

        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(StudentService.class);
        enhancer.setCallbacks(new Callback[] {new MyMethodInterceptor(), new MyMethodInterceptor2()});
        /*
         * 设置多个Callback必须使用CallbackFilter指定在什么情况下使用哪种Callback
         */
        enhancer.setCallbackFilter(new CallbackFilter() {
            @Override
            public int accept(Method method) {
                return 0;
            }
        });
        StudentService studentService = (StudentService) enhancer.create();
        studentService.add();
        studentService.delete();
    }

}
